package com.study.chunguard.common.utils.tree;

import com.fasterxml.jackson.annotation.JsonIgnore;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.List;

/**
 * 树节点的抽象模版类
 *
 * @author zhaowenhao
 * @since 2023-05-06
 */
public abstract class AbstractTreeNode<T, N extends AbstractTreeNode<T, N>> implements TreeNode<T, N> {

    /**
     * 父节点
     */
    private N parent;

    /**
     * 父节点详细信息
     */
    private N parentDetail;

    /**
     * 子节点
     */
    private List<N> children;

    @Override
    @JsonIgnore
    public N getParent() {
        return parent;
    }

    @Override
    public void setParent(N parent) {
        this.parent = parent;
    }

    @Override
    public N getParentDetail() {
        return parentDetail;
    }

    @Override
    public void setParentDetail(N parentDetail) {
        this.parentDetail = parentDetail;
    }

    @Override
    public List<N> getChildren() {
        return this.children;
    }

    @Override
    public void setChildren(List<N> children) {
        this.children = children;
    }

    @Override
    public String toString() {
        final StringWriter stringWriter = new StringWriter();
        TreeNode.printTree(this, new PrintWriter(stringWriter), 0);
        return stringWriter.toString();
    }
}
